<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}

$actions = &$admincp->actions;
$options = array();
foreach( $actions as $k => $v ){
	$options[$k] = $v['title'];
}

if ( $_G['gp_delid'] ){
	if ( $exists_action = fetch('admincp_action', abs(intval($_G['gp_delid']))) ){
		if ( !$exists_action['mixed'] ){
			DB::Delete('admincp_action', abs(intval($_G['gp_delid'])));
			DB::Delete('admincp_action', array(
				'parentid' => abs(intval($_G['gp_delid']))
			));
			Session::Set('notice', '操作成功');
		}else{
			Session::Set('error,', '操作失败');
		}
		redirect();
	}
}

if ( is_post() ){
	$name = $_G['gp_name'] ? htmlspecialchars($_G['gp_name']) : '';
	$title = $_G['gp_title'] ? htmlspecialchars($_G['gp_title']) : '';
	$parentid = $_G['gp_parentid'] ? intval($_G['gp_parentid']) : 0;
	$display = $_G['gp_display'] ? intval($_G['gp_display']) : 0;
	$mixed = $_G['gp_mixed'] ? intval($_G['gp_mixed']) : 0;
	$super = $_G['gp_super'] ? intval($_G['gp_super']) : 0;

	if ( !$name ){
		$msg = '模块名称错误';
	}
	if ( !$title ){
		$msg = '中文名称错误';
	}
	if ( $parentid && !$actions[$parentid] ){
		$msg = '父级选择错误';
	}

	if ( !$msg ){
		DB::Insert('admincp_action', array(
			'name' => $name,
			'parentid' => $parentid,
			'title' => $title,
			'display' => $display,
			'mixed' => $mixed,
			'super' => $super,
		));
		delcache('admincp_action');
		$msg = '操作成功';
	}
	Session::Set('notice', $msg);
	$admincp->redirect('setting', 'actions');
}



?>